// ignore_for_file: prefer_const_constructors, prefer_interpolation_to_compose_strings, prefer_const_literals_to_create_immutables

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../router/app_pages.dart';
import '../DetailView/DetailView.dart';

class HomeView extends StatelessWidget {
  const HomeView({super.key});
  _showSnackbar(Map? result){
    if (result !=null) {
      Get.snackbar(
      "返回值", "success -> " + result["success"].toString()
      );
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
         title: Text("首页"),
         centerTitle: true,
         backgroundColor: Colors.green[300],
      ),
      body: ListView(
        padding: EdgeInsets.symmetric(horizontal: 18),
        children: [
          // 导航
          ListTile(
            title: Text("嵌套导航"),
            subtitle: Text('Get.toNamed(AppRoutes.NestedNavigator)'),
            onTap: () => Get.toNamed(AppRoutes.NestedNavigator),
          ),
          Divider(),
          ListTile(
            title: Text("导航-命名路由 home > list"),
            subtitle: Text('Get.toNamed("/home/list")'),
            // onTap: () => Get.toNamed("/home/list"),
            onTap: () => Get.toNamed(AppRoutes.Home + AppRoutes.List),
          ),
          ListTile(
            title: Text("导航-命名路由 home > list > detail"),
            subtitle: Text('Get.toNamed("/home/list/detail")'),
            onTap: () => Get.toNamed("/home/list/detail"),
            // onTap: () => Get.toNamed(AppRoutes.Detail),
          ),
          ListTile(
            title: Text("导航-类对象"),
            subtitle: Text("Get.to(DetailView())"),
            onTap: () => Get.to(() => DetailView()),
          ),
          ListTile(
            title: Text("导航-清除上一个"),
            subtitle: Text("Get.off(DetailView())"),
            onTap: () => Get.off(DetailView()),
          ),
          ListTile(
            title: Text("导航-arguments传值+返回值"),
            subtitle: Text(
                'Get.toNamed("/home/list/detail", arguments: {"id": 999})'),
            onTap: () async {
              var result = await Get.toNamed("/home/list/detail",
                  arguments: {"id": 999});
              _showSnackbar(result);
            },
          ),
          ListTile(
            title: Text("导航-parameters传值+返回值"),
            subtitle: Text('Get.toNamed("/home/list/detail?id=666")'),
            onTap: () async {
              var result = await Get.toNamed("/home/list/detail?id=666");
              _showSnackbar(result);
            },
          ),
          ListTile(
            title: Text("导航-参数传值+返回值"),
            subtitle: Text('Get.toNamed("/home/list/detail/777")'),
            onTap: () async {
              var result = await Get.toNamed("/home/list/detail/777");
              _showSnackbar(result);
            },
          ),
          ListTile(
            title: Text("导航-not found"),
            subtitle: Text('Get.toNamed("/aaa/bbb/ccc")'),
            onTap: () => Get.toNamed("/aaa/bbb/ccc"),
          ),
          ListTile(
            title: Text("导航-中间件-认证Auth"),
            subtitle: Text('Get.toNamed(AppRoutes.My)'),
            onTap: () => Get.toNamed(AppRoutes.My),
          ),
          Divider(),
          Divider(),
          
          // 组件
          // 顶部弹窗（消息推送弹窗）
          ListTile(
            title: Text("组件-snackbar"),
            subtitle: Text('Get.snackbar("标题","消息",...)'),
            onTap: () => Get.snackbar(
              "snackbar 标题",
              "snackbar 消息",
              // titleText: Text('这是弹出通知框的标题',style: TextStyle(color: Colors.red,fontSize: 30),),
              // messageText: Text('这是弹出通知框的内容',style: TextStyle(color: Colors.blue,fontSize: 20),),
              // snackPosition: SnackPosition.BOTTOM,// 从哪个位置出现弹窗
              // duration: Duration(milliseconds: 5000)// 时间
            ),
          ),
          // 中间弹窗
          ListTile(
            title: Text("组件-dialog"),
            subtitle: Text('Get.defaultDialog(...)'),
            onTap: () => Get.defaultDialog(
              title: "标题",
              content: Column(
                children: [
                  Text("defaultDialog"),
                  Text("defaultDialog"),
                  Text("defaultDialog"),
                ],
              ),
              textConfirm: "确认",// 确认文本
              textCancel: "取消",// 取消文本
              // onConfirm点击确认
              onConfirm: () => Get.back(),// onConfirm这是一个函数回调，当对话框的确认按钮（通常是“确定”或“是”按钮）被点击时会被调用。
              // confirm 点击确认
              //confirm 参数通常预期是一个按钮部件(如TextButton),代表对话框中的确认按钮,你通常不需要直接提供 confirm 参数,因为GetX会为你自动创建一个确认按钮,并绑定到 onConfirm 回调
              // confirm: TextButton(),
              // barrierDismissible: false//禁止点击暗淡区域退出信息框
              // onCancel 点击取消
              // onCancel:() => Navigator.of(context).pop()
            ),
          ),
          // 底部弹窗
          ListTile(
            title: Text("组件-bottomSheet"),
            subtitle: Text('Get.bottomSheet(...)'),
            onTap: () => Get.bottomSheet(
              Container(
                height: 200,
                color: Colors.white,
                child: Column(
                  children: [
                    Text("bottomSheet"),
                    Text("bottomSheet"),
                    Text("bottomSheet"),
                  ],
                ),
              ),
              // isDismissible: false,//禁止点击阴影部分关闭底部窗口
              // enableDrag: false,//禁止采用拖拽的方式关闭底部窗口
            ),

          ),
          Divider(),
          Divider(),

          // state 状态
          ListTile(
            title: Text("State状态-Obx"),
            subtitle: Text('Get.toNamed(AppRoutes.Obx)'),
            onTap: () =>  Get.toNamed(AppRoutes.State + AppRoutes.Obx),
          ),
          ListTile(
            title: Text("State状态-Getx"),
            subtitle: Text('Get.toNamed(AppRoutes.Getx)'),
            onTap: () =>  Get.toNamed(AppRoutes.State + AppRoutes.Getx),
          ),
          ListTile(
            title: Text("State状态-GetBuilder"),
            subtitle: Text('Get.toNamed(AppRoutes.GetBuilder)'),
            onTap: () => Get.toNamed(AppRoutes.State + AppRoutes.GetBuilder),
          ),
           ListTile(
            title: Text("State状态-ValueBuilder"),
            subtitle: Text('Get.toNamed(AppRoutes.ValueBuilder)'),
            onTap: () => Get.toNamed(AppRoutes.State + AppRoutes.ValueBuilder),
          ),
          ListTile(
            title: Text("State状态-Workers"),
            subtitle: Text('Get.toNamed(AppRoutes.Workers)'),
            onTap: () => Get.toNamed(AppRoutes.State + AppRoutes.Workers),
          ),
          Divider(),
          Divider(),

          // 依赖注入
          ListTile(
            title: Text("依赖注入-Put-Find"),
            subtitle: Text('Get.toNamed(AppRoutes.DependencyPutFind)'),
            onTap: () => Get.toNamed(AppRoutes.Dependency + AppRoutes.PutFind),
          ),
          ListTile(
            title: Text("依赖注入-LazyPut"),
            onTap: () =>Get.toNamed(AppRoutes.Dependency + AppRoutes.LazyPut),
            subtitle: Text('Get.toNamed(AppRoutes.LazyPut)'),
          ),
          Divider(),
          Divider(),

          //主题
          ListTile(
            title: Text("主题"),
            subtitle: Text('Get.toNamed(AppRoutes.Theme)'),
            onTap: () => Get.toNamed(AppRoutes.Theme),
          ),
          Divider(),
          Divider(),

          // 多语言
          ListTile(
            title: Text("语言"),
            subtitle: Text('Get.toNamed(AppRoutes.Lang)'),
            onTap: () => Get.toNamed(AppRoutes.Lang),
          ),
          Divider(),
          Divider(),
        ],
      ),
    );
  }
}